<?php

class Sistema_Form_Email extends Zend_Form
{

    public function init()
    {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        $id = $front->getRequest()->getParam('id', 0);
        
        $this->setName('form');
        
        if($id > 0){
            $db = Zend_Db_Table_Abstract::getDefaultAdapter();
            $data = $db->fetchRow('SELECT SQL_CACHE * FROM EMAIL WHERE EML_ID  = ' . $id);
        }
        
        $el = new Zend_Form_Element_Hidden('EML_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('EML_EML');
        $el->setLabel('E-mail');
        $el->setRequired(true);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('EML_STP');
        $el->setLabel('SMTP');
        //$el->setRequired(true);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('EML_USU');
        $el->setLabel('Usuário');
        //$el->setRequired(true);
        $this->addElement($el);
        
        //$el = new Zend_Form_Element_Password('EML_SNH');
        //$el->setLabel('Senha');
        //$el->setRequired(true);
        //$this->addElement($el);
        $html = '<input type="password" name="EML_SNH" id="EML_SNH" value="'.$data['EML_SNH'].'">';
        $el = new Zend_Form_Element('EML_SNHS',array( 'helper'=>'formNote', 'value'=> $html ));
        $el->setLabel('Senha');
        $this->addElement($el);
        
        
        $arr = array(
            '' => '',
            'contato'   => 'Contato',
            'interesse' => 'Interesse por produto',
        );
        asort($arr);
        $el = new Zend_Form_Element_Select('EML_MOD',array('onchange' => ''));
        $el->setLabel('Módulo');
        $el->setRequired(true);
        $el->addMultiOptions($arr);
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Checkbox('EML_STA',array('checked'=>'checked'));
        $el->setLabel('Ativo');
        $this->addElement($el);
        
        
        $btn = new Zend_Form_Element_Submit('Salvar',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-frm">Cancelar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
     
    }


}

